package com.ssc.demo1;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class Consumer{
    private static final String BROKER_URL="tcp://49.234.233.179:61616";
    public static void main(String[] args){
        //连接工厂
        ConnectionFactory connectionFactory=null;
        //连接实例
        Connection connection=null;
        //收发线程
        Session session=null;
        //消息发送目标地址
        Destination destination=null;
        try {
            //实例化连接工厂
            connectionFactory=new ActiveMQConnectionFactory("ssc", "ssc", BROKER_URL);
            //获取连接实例
            connection=connectionFactory.createConnection();
            //启动连接
            connection.start();
            //创建接收和发送的线程实例
            session=connection.createSession(Boolean.FALSE,Session.AUTO_ACKNOWLEDGE);
            //创建一个消息队列
            destination=session.createQueue("test1.mq.queue");
            //创建消息消费者
            MessageConsumer messageConsumer=session.createConsumer(destination);
            //创建消息监听
            messageConsumer.setMessageListener(new MQListener());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
